﻿using Common;
using MVP;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WinForms
{
    public partial class PeriodBulan : Form, IPeriodBulanView
    {
        private PeriodBulanPresenter _presenter;

        public PeriodBulan()
        {
            _presenter = new PeriodBulanPresenter(this);
            InitializeComponent();
            InvokeInitialize(new EventArgs());
        }

        #region IPeriodBulanView Members

        public IList<string> Months
        {
            set { bulanComboBox.DataSource = value; }
        }

        public EnumMonth Month
        {
            get { return Enums.GetMonthByName(bulanComboBox.SelectedItem.ToString()); }
        }

        public int Year
        {
            get
            {
                return (int)tahunNumericUpDown.Value;
            }
            set
            {
                tahunNumericUpDown.Value = value;
            }
        }
        public event EventHandler Initialize;
        #endregion

        private void cancelButton_Click(object sender, EventArgs e)
        {
            this.Dispose();
            this.Close();
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            this.Dispose();
            this.Close();
        }

        public void InvokeInitialize(EventArgs e)
        {
            EventHandler handler = Initialize;
            if (handler != null)
            {
                handler(this, e);
            }
        }

    }

    public static class SelectPeriodBulanBox
    {
        public static String[] Show()
        {
            PeriodBulan periodBulan = new PeriodBulan();
            if (periodBulan.ShowDialog() == DialogResult.OK)
            {
                return new String[] { periodBulan.Month.ToString(), periodBulan.Year.ToString() };
            }

            return null;
        }
    }
}
